package day16;

public class Student implements Comparable<Student>{

	public Student() {
		
	}

	public Student(String name, int age) {
		this.name = name;
		this.age = age;
	}

	private String name;
	
	private int age;

	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	@Override
	public String toString() {
		return "Student [name=" + name + ", age=" + age + "]";
	}

	@Override
	public int hashCode() {
		return this.name.hashCode() + this.age * 37;
	}

	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof Student)) {
			throw new ClassCastException("传入的类型不匹配，学生类型不能和其他类型进行比较");
		}
		Student student = (Student) obj;
		return this.name.equals(student.name) && this.age == student.age;
	}

	/**
	 * 按名字
	 * @param student
	 * @return
	 */
	@Override
	public int compareTo(Student student) {
		int num = this.name.compareTo(student.name);
		if (num == 0) {
			return this.age - student.age;
		}
		return num;
	}
	
	
	
	
}
